package main

import (
	"fmt"
)

type link struct {
	plug int
	mod  int
	pwr  int
}

type mod_info struct {
	plug_idx int
	pwr      int
}

var plug_pwr = []int{80, 80, 80, 80, 130, 0, 0, 0, 0, 0}
var req_list = []int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

var req_plug = []int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
var mod_out = []int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0}

var ship_map = make(map[string]bool)

func abs(num int) int {
	if num < 0 {
		return -num
	}
	return num
}

var plug_num = 10

func main() {
	fmt.Println(plug_pwr)
	for i := 0; i < plug_num; i++ {
		for j := 0; j < plug_num; j++ {
			if abs(i-j) <= 2 {
				ship_map[fmt.Sprintf("%d-%d", i, j)] = true
				continue
			}
			if i < j {
				if i+plug_num-j <= 2 {
					ship_map[fmt.Sprintf("%d-%d", i, j)] = true
					continue
				}
			}
			if j < i {
				if j+plug_num-i <= 2 {
					ship_map[fmt.Sprintf("%d-%d", i, j)] = true
					continue
				}
			}
			ship_map[fmt.Sprintf("%d-%d", i, j)] = false
		}
	}

	for plug_idx := 0; plug_idx < plug_num; plug_idx++ {
		if plug_pwr[plug_idx] == 0 {
			continue
		}
		if plug_pwr[plug_idx] > 40 {
			req_list[plug_idx] = plug_pwr[plug_idx] - 40
			mod_out[plug_idx] = 40
		} else {
			req_list[plug_idx] = 0
			mod_out[plug_idx] = req_list[plug_idx]
		}
	}

	fmt.Println(req_list)
	fmt.Println(mod_out)

	for kk := 0; kk < len(plug_pwr); kk++ {
		fmt.Println("----------------")
		grv_list := []link{}

		for plug_idx := 0; plug_idx < plug_num; plug_idx++ {
			if req_list[plug_idx] == 0 {
				continue
			}
			can_usb_mod := []int{}
			for mod_idx := 0; mod_idx < plug_num; mod_idx++ {
				if mod_out[mod_idx] == 0 && ship_map[fmt.Sprintf("%d-%d", plug_idx, mod_idx)] {
					can_usb_mod = append(can_usb_mod, mod_idx)
				}
			}
			fmt.Println(can_usb_mod)
			for mod := 0; mod < len(can_usb_mod); mod++ {
				grv_list = append(grv_list, link{plug_idx, can_usb_mod[mod], req_list[plug_idx] / len(can_usb_mod)})
			}
		}
		if len(grv_list) == 0 {
			break
		}
		max_pwr := 0
		max_idx := 0xff

		for idx := 0; idx < len(grv_list); idx++ {
			if grv_list[idx].pwr > max_pwr {
				max_pwr = grv_list[idx].pwr
				max_idx = idx
			}
		}

		fmt.Println(grv_list)
		fmt.Println(max_idx)

		if req_list[grv_list[max_idx].plug] >= 40 {
			req_list[grv_list[max_idx].plug] = req_list[grv_list[max_idx].plug] - 40
			mod_out[grv_list[max_idx].mod] = 40
		} else {
			req_list[grv_list[max_idx].plug] = 0
			mod_out[grv_list[max_idx].mod] = req_list[grv_list[max_idx].plug]
		}

		fmt.Println(req_list)
		fmt.Println(mod_out)
	}

}
